package com.onpositive.dataminer.userstorage;

import com.onpositive.semantic.model.api.command.DefaultCommandFactory;
import com.onpositive.semantic.model.api.command.ICommandExecutor;
import com.onpositive.semantic.model.api.command.ICommandFactory;
import com.onpositive.semantic.model.api.command.IHasCommandExecutor;
import com.onpositive.semantic.model.api.meta.BaseMeta;
import com.onpositive.semantic.model.api.meta.IMeta;
import com.onpositive.semantic.model.api.property.IProperty;

public class UserProperty implements IProperty ,IHasCommandExecutor{

	protected BaseMeta baseMeta = new BaseMeta();
	
	
	protected String id;
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		UserProperty other = (UserProperty) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

	protected UserValueStorage vl;

	public UserProperty(String id, UserValueStorage vl) {
		super();
		this.id = id;
		baseMeta.registerService(IHasCommandExecutor.class,this);
		this.vl = vl;
	}

	@Override
	public IMeta getMeta() {
		return baseMeta;
	}

	@Override
	public String getId() {
		return id;
	}

	@Override
	public Object getValue(Object obj) {
		return vl.getValue(obj, id);
	}

	@Override
	public ICommandExecutor getCommandExecutor() {
		return vl;
	}

	@Override
	public ICommandFactory getCommandFactory() {
		return DefaultCommandFactory.INSTANCE;
	}

}
